package com.uwaterloo.jobmineplus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

import com.uwaterloo.jobmineplus.backend.ResourceRequest;
import com.uwaterloo.jobmineplus.backend.UserContextDao;
import com.uwaterloo.jobmineplus.data.Interview;
import com.uwaterloo.jobmineplus.mock.MockResourceRequest;
import com.uwaterloo.jobmineplus.mock.MockUserContextDao;

public class InterviewTab extends ListActivity{
	private static final UserContextDao userContextDao = MockUserContextDao.getInstance();
	
	private static final String COMPANY = "Company";
	private static final String POSITION = "Position";
	private static final String LOCATION = "Location";
	private static final String TYPE = "Type";
	private static final String INTERVIERS = "Interviewers";
	private static final String TIME = "Time";
	
	private Set<Interview> interviews;
	private ResourceRequest resRequest;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.interview_list);
		resRequest = new MockResourceRequest();
		interviews = userContextDao.getInterviews(resRequest);
		
		populateInteviews();
	}
	
	private void populateInteviews() {
		List<Map<String, String>> interviewInfo = getInterviewInfoMap();
		
		String[] from = new String[] {COMPANY, LOCATION, POSITION, LOCATION,TYPE,INTERVIERS,TIME};
		int[] to = new int[]{R.id.companyName, R.id.location,R.id.position,R.id.location,R.id.type,R.id.interviewers,R.id.time};
		
		SimpleAdapter simpleAdapter = 
			new SimpleAdapter(this, interviewInfo, R.layout.interview_row, from, to);
		setListAdapter(simpleAdapter);
	}
	
	private List<Map<String, String>> getInterviewInfoMap() {
		List<Map<String, String>> infoMapList = new ArrayList<Map<String, String>>();
		for(Interview interview : interviews){
			Map<String, String> infoMap = new HashMap<String, String>();
			infoMap.put(COMPANY, interview.getCompany());
			infoMap.put(POSITION, interview.getposition());
			infoMap.put(LOCATION, interview.getLocation().toString());
			infoMap.put(TYPE, interview.getType().toString());
			infoMap.put(INTERVIERS, "John Doe");
			infoMap.put(TIME, "No Time Specified yet");
			
			infoMapList.add(infoMap);
		}
		return infoMapList;
	}
}
